#
# this module look for libxml (http://http://xmlsoft.org) support
# it will define the following values
#
# LIBXML_INCLUDE_PATH = where libxml/parser.h can be found
# LIBXML_LIBRARY      = the library to link against libxml2
#

FIND_LIBRARY(LIBXML_LIBRARY xml2 
             /usr/lib 
             /usr/local/lib
             /sw/lib
             /u0/jkim/lib/lib 
             lib
)
FIND_PATH(LIBXML_INCLUDE_DIR libxml/parser.h 
          /usr/include/libxml2
          /usr/local/include/libxml2
          /sw/include/libxml2
          /u0/jkim/lib/include/libxml2
          include/libxml2
)

IF(NOT LIBXML_LIBRARY)
  MESSAGE(STATUS "libxml is not found in pre-defined paths.")
  MESSAGE(STATUS "We are using the version packaged with OHMMS instead.")
  MESSAGE(STATUS "NOTE!!! Don't worry.  We are not installing anything")
  MESSAGE(STATUS "to anywhere except to the OHMMS project directory.")
  IF(UNIX)
    IF(RUN_CONFIGURE)
      EXEC_PROGRAM(
       "${AUXPACKAGES}/libxml2/configure --prefix=${PROJECT_BINARY_DIR} --with-cc=${CMAKE _CC_COMPILER}"
        ${AUXPACKAGES}/libxml2
      )
      EXEC_PROGRAM(make ${AUXPACKAGES}/libxml2)
      EXEC_PROGRAM(make ${AUXPACKAGES}/libxml2 ARGS install)
      FIND_LIBRARY(LIBXML_LIBRARY xml2 ${PROJECT_BINARY_DIR}/lib)
      FIND_PATH(LIBXML_INCLUDE_DIR libxml/parser.h ${PROJECT_BINARY_DIR}/include/libxml2)
    ENDIF(RUN_CONFIGURE)
  ENDIF(UNIX)
ENDIF(NOT LIBXML_LIBRARY)

IF(LIBXML_LIBRARY)
  MARK_AS_ADVANCED(LIBXML_INCLUDE_DIR LIBXML_LIBRARY)
  INCLUDE_DIRECTORIES(${LIBXML_INCLUDE_DIR})
  SET(HAVE_LIBXML2 1)
#  LINK_LIBRARIES(${LIBXML_LIBRARY})
ENDIF(LIBXML_LIBRARY)
